﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>$title</title>
    <script src="../../../../Js/jquery-1.11.0.js"></script><!--在模板文件中使用外部文件时一定要用决对路径-->
    <script src="../../../../ckeditor/ckeditor.js" type="text/javascript"></script>
   <script type="text/javascript">
       $(function () {
    //       CKEDITOR.replace('txtContent',
	//{
	//    extraPlugins: 'bbcode',
	//    removePlugins: 'bidi,button,dialogadvtab,div,filebrowser,flash,format,forms,horizontalrule,iframe,indent,justify,liststyle,pagebreak,showborders,stylescombo,table,tabletools,templates',
	//    toolbar:
	//	[
	//		['Source', '-', 'Save', 'NewPage', '-', 'Undo', 'Redo'],
	//		['Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
	//		['Link', 'Unlink', 'Image'],
	//		'/',
	//		['FontSize', 'Bold', 'Italic', 'Underline'],
	//		['NumberedList', 'BulletedList', '-', 'Blockquote'],
	//		['TextColor', '-', 'Smiley', 'SpecialChar', '-', 'Maximize']
	//	],
	//    smiley_images:
	//	[
	//		'regular_smile.gif', 'sad_smile.gif', 'wink_smile.gif', 'teeth_smile.gif', 'tounge_smile.gif',
	//		'embaressed_smile.gif', 'omg_smile.gif', 'whatchutalkingabout_smile.gif', 'angel_smile.gif', 'shades_smile.gif',
	//		'cry_smile.gif', 'kiss.gif'
	//	],
	//    smiley_descriptions:
	//	[
	//		'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise',
	//		'indecision', 'angel', 'cool', 'crying', 'kiss'
	//	]
	//});
           loadComment(); //加载评论
           $("#btn").click(function () {
               debugger;
               //var msg = $("#txtContent").val();
               var oEditor = CKEDITOR.instances.txtContent; //找到编辑器
               var str1 = oEditor.skinPath.split("ckeditor")[0];
               var msg = oEditor.getData();//获取编辑器中的值
               var _content = oEditor.document.getBody().getText();
               msg = msg.replace(str1, "../../../../");
               //msg = msg.replace("<", "&lt;").replace(">", "&gt;");//一定要过滤掉危险的字符。
               msg = msg.replace(/</g, "&lt;");
               msg = msg.replace(/>/g, "&gt;");
               if (msg != "") {
                   $.post("../../../../Action/BookComment.ashx", { "action": "postComment", "msg": msg,"content":_content, "bookId": $bookId }, function (data) {
                       if (data == "yes") {
                           alert("评论成功");
                           loadComment(); //加载评论
                       } else if (data == "err") {
                           alert("你输入的内容中包含禁用词！！");
                       } else
                       {
                           alert("你输入的内容中包含审查词！！");
                       }
                   });
               } else {
                   alert("请输入内容!!")
               }
           });
           $("img[carType=car]").click(addToCar);
       });
       function addToCar() {
           debugger;
           //1.用ajax发送数据到服务器
           //1.1获取要购买的 产品id
           //1.2将 产品id 发送到服务器
           $.post("../../../../Action/car.ashx", { type: "ac", pid: $bookId }, function (jsObj) {
               if (jsObj.statu == "ok")
               {
                   window.location = "../../../../View/Car.aspx";
               }
           }, "json");

       }
        function loadComment() {
            $.post("../../../../Action/BookComment.ashx", { "action": "load", "bookId": $bookId }, function (data) {
                var comments = $.parseJSON(data);
                $("#txtComment").html("");
                for (var i = 0; i < comments.data.length; i++) {
                    var strhtml = comments.data[i].Msg;
                    strhtml = strhtml.replace(/&lt;/g, "<");
                    strhtml = strhtml.replace(/&gt;/g, ">");
                    $("<li>" + comments.data[i].CreateDateTime + ":" + strhtml + "</li>").appendTo("#txtComment");                                
                }
                $("li p").css("margin", "-17px 0 0 76px");
            });
        }
    </script>
</head>
<body>
$body
<textarea id="txtContent" rows="20" cols="60"></textarea><br />
    <script type="text/javascript">
        //<![CDATA[
        // Replace the <textarea id="editor1"> with an CKEditor instance.
        var editor = CKEDITOR.replace('txtContent');
        //]]>
    </script>
<input type="button" value="发布评论" id="btn" /><br />
<img src="../../../../images/buy.gif " style="cursor:pointer;" cartype="car" />
    <ul id="txtComment"></ul>
</body>
</html>
